
var Logger = function () {
    return {
        console_log: function (msg, error) {
            if (error) {
                if (error.message && error.stack) {
                    console.log(msg, "Casued by " + error.stack);
                } else if (error.message)
                    console.log(msg, "Casued by: \"" + error.message + "\"");
            }
        },

        str_error: function (error) {
            var msg = null;
            if (error) {
                if (error.message && error.stack) {
                    msg = "messge: " + error.message + "\nstack: " + error.stack;
                } else if (error.message)
                    console.log("messge:" + error.message);
            } else
                msg = "";
            return msg;
        },

        json_error: function (error) {
            var msg = {};
            if (error) {
                if (error.message)
                    msg.messge = error.message;
                if (error.stack)
                    msg.stack = error.stack;
            }
            return msg;
        },

        jstr_error: function (error) {
            return JSON.stringify(this.json_error(error));
        }
    }


}
const logger = Logger();
// print catch error
try {
    throw new Error("test error");
} catch (error) {
    // console.log("read config.json error. " + error.message + error.stack);
    logger.console_log("read config.json failed", error);
    console.log(logger.str_error(error));
    console.log(logger.jstr_error(error));
}
